package com.demo.jianjunhuang.activitylifecycle;

import android.app.Activity;
import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Bundle;
import android.util.Log;

/**
 * @author jianjunhuang.me@foxmail.com
 * @since 2017/5/20.
 */

public class MainApplication extends Application implements ActivityLifecycleCallbacks {

  @Override public void onCreate() {
    super.onCreate();
    registerActivityLifecycleCallbacks(this);
  }

  private static final String TAG = "MainApplication";

  @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    Log.i(TAG, "onActivityCreated: "+activity.getLocalClassName()+" created ");
  }

  @Override public void onActivityStarted(Activity activity) {
    Log.i(TAG, "onActivityStarted: "+activity.getLocalClassName()+" started ");
  }

  @Override public void onActivityResumed(Activity activity) {
    Log.i(TAG, "onActivityResumed: "+activity.getLocalClassName()+" resumed");
  }

  @Override public void onActivityPaused(Activity activity) {
    Log.i(TAG, "onActivityPaused: "+activity.getLocalClassName()+" paused");
  }

  @Override public void onActivityStopped(Activity activity) {
    Log.i(TAG, "onActivityStopped: "+activity.getLocalClassName()+" stopped");
  }

  /**
   * 该方法只有在另一个 Activity 压栈时才会调用 ，出栈时不调用 （onStop 前调用）
   * @param activity
   * @param outState
   */
  @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
    Log.i(TAG, "onActivitySaveInstanceState: "+activity.getLocalClassName()+" save instance state");
  }

  @Override public void onActivityDestroyed(Activity activity) {
    Log.i(TAG, "onActivityDestroyed: "+activity.getLocalClassName()+" destroyed");
  }
}
